﻿using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Web;
using YiSha.Admin.Web.Controllers;
using YiSha.Basics;
using YiSha.Entity.OrganizationManage;
using YiSha.Enums;
using YiSha.Model;
using YiSha.Model.Param.OrganizationManage;
using YiSha.Service.OrganizationManage;
using YiSha.Util.Model;

namespace YiSha.Admin.Web.Areas.OrganizationManage.Controllers
{
    /// <summary>
    /// 职务控制器
    /// </summary>
    [Area("OrganizationManage")]
    public class PositionController : BaseController
    {
        public PositionService positionBLL { get; set; }

        #region 视图功能
        [AuthorizeFilter("organization:position:view")]
        public IActionResult PositionIndex()
        {
            return View();
        }

        public IActionResult PositionForm()
        {
            return View();
        }
        #endregion

        #region 获取数据
        /// <summary>
        /// 查询数据
        /// </summary>
        /// <param name="param"></param>
        /// <returns></returns>
        [HttpGet]
        [AuthorizeFilter("organization:position:search,organization:user:view")]
        public IActionResult GetListJson(PositionListParam param)
        {
            TData<List<PositionEntity>> obj = positionBLL.GetList(param);
            return Json(obj);
        }

        [HttpGet]
        [AuthorizeFilter("organization:position:search,organization:user:view")]
        public IActionResult GetPageListJson(PositionListParam param, Pagination pagination)
        {
            TData<List<PositionEntity>> obj = positionBLL.GetPageList(param, pagination);
            return Json(obj);
        }

        [HttpGet]
        public IActionResult GetFormJson(string id)
        {
            TData<PositionEntity> obj = positionBLL.GetEntity(id);
            return Json(obj);
        }


        [HttpGet]
        public IActionResult GetPositionName(PositionListParam param)
        {
            TData<string> obj = new TData<string>();
            var list = positionBLL.GetList(param);
            if (list.MsgCode == MsgCode.Success)
            {
                obj.Data = string.Join(",", list.Data.Select(p => p.PositionName));
            }
            return Json(obj);
        }
        #endregion

        #region 提交数据
        [HttpPost]
        [AuthorizeFilter("organization:position:add,organization:position:edit")]
        public IActionResult SaveFormJson(PositionEntity entity)
        {
            TData obj = positionBLL.SaveForm(entity);
            return Json(obj);
        }

        [HttpPost]
        [AuthorizeFilter("organization:position:delete")]
        public IActionResult DeleteFormJson(List<string> ids)
        {
            TData obj = positionBLL.DeleteForm(ids);
            return Json(obj);
        }
        #endregion
    }
}